/*
 * File:   StrategyGene.h
 * Author: root
 *
 * Created on November 20, 2008, 8:41 PM
 */

#ifndef _STRATEGYGENE_H
#define	_STRATEGYGENE_H

#include <string>
#include <sstream>

using namespace std;

class StrategyGene {

    string strategyName;
    int weight;
    int* parameters;
    const int numParameters;

public:

    StrategyGene(const string& name, int strategyWeight, int* parameterArray, int parametersSize)
    : strategyName(name), weight(strategyWeight), numParameters(parametersSize)
    {
        parameters = new int[numParameters];
        for (int i = 0; i < numParameters; i++) {
            parameters[i] = parameterArray[i];
        }
    }

    StrategyGene(const string&, int);   // For random initialization of parameters

    string getStrategyName() const  { return strategyName; }

    void mutateWeight();
    int getWeight() const       { return weight; }
    void setWeight(int value)   { weight = value; }

    void mutateParameters();
    void mutateParameter(int);
    int getParametersSize() const   { return numParameters; }

    int getParameter(int index) const
    {
        if (index >= 0 && index < numParameters) return parameters[index]; else return -1;
    }

    void setParameter(int index, int value)
    {
        if (index >= 0 && index < numParameters) parameters[index] = value;
    }

    string toString() const {
        ostringstream retBuilder;
        retBuilder << "Strategy: " << strategyName;
        retBuilder << "\nWeight: " << weight;
        retBuilder << "\nNumParameters: " << numParameters;
        if (numParameters > 0) {
            retBuilder << "\nParameterList:\n";
            retBuilder << parameters[0];
            for (int i = 1; i < numParameters; i++) {
                retBuilder << ", " << parameters[i];
            }
        }
        return retBuilder.str();
    }

    string toShortString() const {
      ostringstream retBuilder;
      retBuilder << "Strategy: " << strategyName;
      retBuilder << "    Weight: " << weight;
      if (numParameters > 0) {
        retBuilder << "    ParameterList: ";
        retBuilder << parameters[0];
        for (int i = 1; i < numParameters; i++) {
          retBuilder << ", " << parameters[i];
        }
      }
      return retBuilder.str();
    }

    string toCompactString() const {
        ostringstream retBuilder;
        retBuilder << strategyName << ":";
        retBuilder << weight << ":";
        retBuilder << numParameters;
        if (numParameters > 0) {
            for (int i = 0; i < numParameters; i++) {
                retBuilder << ":" << parameters[i];
            }
        }
        return retBuilder.str();
    }

    virtual ~StrategyGene() {
        delete []parameters;
    }

private:
    static int randomValue();

};

#endif	/* _STRATEGYGENE_H */

